home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Mac OS Development Toolkit / Automation Essentials 2.3.0 / Host Automation Folder / SPEC Libs / TargetCheck.Lib < prev    next >
Encoding:
Text File  |  1998-03-19  |  29.6 KB  |  827 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:        TargetCheck.Lib
  5. #
  6. #    Contains:    xxx put contents here xxx
  7. #
  8. #    Written by:    KTA, KL, ML, GS et al
  9. #
  10. #    Copyright:    © 1993-1995 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #     <1.1.3>    11/16/95    ML        Added SystemFileInfo()
  19. #     <1.1.2>      4/11/95    KTA        Moved IsPowerPC() from Gestalt.lib and created a new task
  20. #                                    IsSystem7().
  21. #     <1.1.1>      3/3/95    ML        RecordGetAboutThisMacintosh() - comment out system size until
  22. #                                    MemoryMonitor bug is fixed, move all memory size results to TCS
  23. #                                    Num field
  24. #    <1.1.0>          2/16/95    KTA        MachineState() - Readded MonitorInfo
  25. #    .0.1112>     2/15/95    ML        GetRomBuild() - if fail, return string instead of undefined.
  26. #    .0.1111>     1/31/95    KTA        GetROMBuild() - Print error message when old version of
  27. #                                    MemoryMonitor
  28. #    .0.1110>     1/19/95    KTA        Changed the name of ExceptionHandler() to ExceptionDispatcher().
  29. #    1.0.119>     1/16/95    KTA        MachineState() - Added pUseXTools.
  30. #    1.0.118>     1/16/95    KTA        MachineState() - added OSVersion, and ROMBuild,    GetROMBuild() -
  31. #                                    created
  32. #    1.0.117>     1/11/95    KTA        RecordMonitorInfo() - Changed it so doesn't call MachineState()
  33. #                                    and simplified.
  34. #    1.0.116>     1/11/95    KTA        MachineState() - Removed gestalt support for VU 2.0.1 (two
  35. #                                    shorts), Removed FormLongNumber() and all dependancies 
  36. #                                    on the MathTool.Lib and MathTool.
  37. #    1.0.115>    12/13/94    KTA        
  38. #    1.0.114>    12/12/94    ML        Remove gTestCaseLoggingMethod, revise filetool calls to
  39. #                                    _Filetool calls, revise MemoryMonitor calls to _MemoryMonitor
  40. #                                    calls, remove Filetool.vulib and MemoryMonitor.vulib from
  41. #                                    library declarations.
  42. #    1.0.113>    12/12/94    ML        Removed gLogLevel, replace w/gDisableAllLogging
  43. #    1.0.112>     12/5/94    ML        Added Exception Handling support
  44. #    1.0.111>     11/3/94    KTA        Refixed some old code that got back into Restart() - now
  45. #                                    selecting Restart menuitem by ordinality.
  46. #    1.0.110>     9/21/94    ML        Revise gestalt calls in MachineState() for         VU 2.1
  47. #                                    support, ProfileApplication() - Check globals
  48. #                                    gAddSuiteInfoFieldsRE and gAdditionalSuiteInfoFT before
  49. #                                    resetting
  50. #    <1.0.19>     9/19/94    KTA        Restart() -Made several fixes to support Powertalk whixh takes
  51. #                                    longer to reboot (result = No_Error).
  52. #    <1.0.18>     7/18/94    KTA        Restart() - Added support for PowerBooks - they add a sleep
  53. #                                    menuitem.
  54. #    <1.0.17>     5/10/94    ML        Check for modal before Profiling application
  55. #    <1.0.16>     4/13/94    KTA        Changed the name of RecordRamFootPrint() to
  56. #                                    RecordGetAboutThisMacintosh().
  57. #    <1.0.15>     4/11/94    KTA        MachineState() - Removed an instance of SystemArch that hadn't
  58. #                                    been removed.
  59. #    <1.0.14>      4/8/94    ML        Removed hanging TCSEnd() and revised params for TCSStart
  60. #                                    and end in RecordGetAboutThisMacintosh().
  61. #                                    in RecordGetAboutThisMacintosh().
  62. #    <1.0.13>     3/29/94    KTA        Restart() - Use ordinality instead of strings.
  63. #    <1.0.12>     3/28/94    KTA        Added <Tool>Operations.Lib and moved some tasks into them.
  64. #    <1.0.11>     3/23/94    KTA        Added marks
  65. #    <1.0.10>     3/23/94    KTA        MachineState() - Removed System Arch.
  66. #     <1.0.9>     3/19/94    ML        Revised RecordGetAboutThisMacintosh for appname in TCSEnd
  67. #     <1.0.8>     3/17/94    ML        added ProfileApplication()
  68. #     <1.0.7>     3/16/94    ML        moved non-gestalt tasks here from gestalt.lib, added
  69. #                                    RecordGetAboutThisMacintosh() and RecordMonitorInfo() tasks.
  70. #     <1.0.6>     9/29/93    KTA        Removed TargetCheck(), OpenCDEV(which), CloseCDEV(which),
  71. #                                    SwitchAddressing(value) SwitchVM(state), SwitchFS(state),
  72. #                                    SwitchCache(state) because there were buggy and no one
  73. #                                    was(could) using them
  74. #     <1.0.5>     8/25/93    KTA        TargetCheck() - BugFix where turning VM off wasn't handled
  75. #                                    properly.
  76. #     <1.0.4>     7/15/93    KTA        Updated References to tasks in Gestalt.lib whos names were
  77. #                                    changed. Took out code to turn VM down - SwitchVM().  Took out
  78. #                                    releasetarget prior to restart if restartNecessary -
  79. #                                    TargetCheck().  Removed checks for Undef, before checking state.
  80. #     <1.0.3>      6/8/93    NAGA    Unmark tasks that are not published
  81. #     <1.0.2>     5/21/93    NAGA    Adding header and porting old files to follow new standards
  82. #
  83. # ****************************************************************************
  84. #
  85.  
  86. ########################################################################
  87. #                            External libraries 
  88. #=======================================================================
  89. Libraries 'Output.Lib', "MemoryMonitorOperations.lib", 
  90. "Globals.Lib", "UserInterface.Lib", "TCS.Lib", "Gestalt.Lib", "OnTarget.Lib", 
  91. "OnTargetOperations.Lib", "FileToolOperations.Lib",
  92. "ExceptionHandling.Lib","String.Lib";
  93.  
  94. #########################################################################
  95. #                            SystemFileInfo( pFileType )
  96. #========================================================================
  97. # Author:        ML
  98. # Description:    Provides info on the targets system files
  99. # Parameters:    pFileType:    'extn' - info on extensions
  100. #                            'ctrl' - info on control panels
  101. #                            'macs' - info on system folder root files
  102. # Returns:        0 - Failure
  103. #                List of list of file name, list of type, version, i.e.
  104. #                {
  105. #                    { 'PrintMonitor',{ 'APPL','7.1.2' } },
  106. #                    ' EM Extension',{ 'INIT','3.0' } }, ...
  107. #                }
  108. #
  109. # Examples:        SystemFileInfo('extn');
  110. # Assumptions:    Finder Scripting Extension, program linking, guest access
  111. #                must be installed and enabled on target for this task 
  112. #                to succeed.
  113. # Notes:        List returned is optimized for obtaining info based on file
  114. #                name, i.e. assoc ("Monitors", SystemFileInfo( 'ctrl' ));
  115. #                will return {type, version} of the Monitors cDev.
  116. #========================================================================
  117. # History:
  118. # ML    11/16/95    created
  119. #########################################################################
  120. Task SystemFileInfo( pFileType )
  121. begin
  122.     returnval := 0;
  123.     switch pFileType
  124.     begin
  125.         case 'extn':
  126.             folderName := 'extensions';
  127.         case 'ctrl':
  128.             folderName := 'control panels';
  129.         case 'macs':
  130.             folderName := 'system';
  131.         default:
  132.         begin
  133.             logstr("!@#$% - pFileType must be either 'extn', 'ctrl', or 'macs'." );
  134.             return returnval;
  135.         end;
  136.     end;
  137.     #println folderName;
  138.     getFileInfoScript :=
  139.     'tell application "Finder" of machine "' + "{global gMachineName}" +  '"
  140.         set namelist to {name} of files in ' + "{folderName}" +  ' folder
  141.         set typelist to {file type} of files in ' + "{folderName}" +  ' folder
  142.         try
  143.             set verslist to {version} of files in ' + "{folderName}" +  ' folder
  144.             set theList to namelist & typelist & verslist
  145.         on error
  146.             set verslist to {}
  147.             repeat with n in files in ' + "{folderName}" +  ' folder
  148.                 try
  149.                     set currlist to {version} of n
  150.                 on error
  151.                     set currlist to {"n/a"}
  152.                 end try
  153.                 set verslist to verslist & currlist
  154.             end repeat
  155.             set theList to namelist & typelist & {verslist}
  156.         end try
  157.         return theList
  158.     end tell';
  159.     #println getFileInfoScript;
  160.     fileInfoList := applescriptstring(getFileInfoScript);
  161.     if (fileInfoList[1] = 0)
  162.     begin
  163.         fileInfoList := fileInfoList[2];
  164.         #println fileInfoList;
  165.         numItems := card(fileInfoList[1]);
  166.         #println numItems;
  167.         typeVersList := {};
  168.         theList := {};
  169.         for i := 1 to numitems
  170.         begin
  171.             typeVersList := {fileInfoList[2][i], fileInfoList[3][i]};
  172.             theList := insert({fileInfoList[1][i], typeVersList},
  173.                                 card(theList) + 1, theList);
  174.         end;
  175.         returnval := theList;
  176.     end;
  177.     else
  178.         LogStr("!@#$% - Problem with Applescript. Is Finder Scripting Extension 
  179.                 installed, Program linking and Guest access enabled?");
  180.     return returnval;
  181. end;
  182.  
  183. #########################################################################
  184. #                            Restart()
  185. #========================================================================
  186. # Author:        RV
  187. # Description:    Restarts and reaquires Targets
  188. # Parameters:    None
  189. # Returns:        1 - Success
  190. #                0 - Failure
  191. # Examples:        Restart();
  192. # Assumptions:    None 
  193. #========================================================================
  194. # History:
  195. # KTA    7/14/93     Changed some of the logging and added global restartNecessary := 0;
  196. # KTA    3/29/94     SelectMenuItem by Ordinality, longer wait.
  197. # KTA    7/18/94     Added support for PowerBook - they add a sleep menuitem.
  198. # KTA    9/19/94     Made several fixes to support Powertalk whixh takes longer to 
  199. #                 reboot (result = No_Error).
  200. # ML    11/29/94    Added Exception Handling support
  201. # ML    12/12/94    Removed gLogLevel, replace w/gDisableAllLogging
  202. #########################################################################
  203. TASK Restart(Time_to_restart := 25) 
  204. begin
  205.     global gDisableAllLogging;
  206.     No_Error := 0;
  207.     Target_Not_Found := 3; #error codes returned by acquireTarget/releaseTarget
  208.     Target_Failure := 1;   #error codes returned by acquireTarget/releaseTarget
  209.  
  210.     try match[application t:?AppTitle];
  211.     catch theError
  212.         ExceptionDispatcher(theError);
  213.     if not(AppTitle = 'Finder')
  214.         _select([menuItem t:'Finder']!,1);
  215.         
  216.     theMenuItems := _collect([menuItem m:[menu o:6]]!,1);
  217.     WhichMenu := Card(theMenuItems)-1;        # Restart menuitem is second from the bottom in the Special menu
  218.                                             # except on Powerbooks which add two menuitems including - 'Sleep'
  219.  
  220.     try match[target t:?target_name z:?target_zone];    # Get the target name and zone through unification
  221.     catch theError
  222.         ExceptionDispatcher(theError);
  223.     global restartNecessary := 0;
  224.  
  225.     theMI := _match ([MenuItem o:WhichMenu m:[menu o:6]]!,1);    # Test to see if PowerBook menuitems were added
  226.     if(theMI.t = '-') and (theMI.e = false)
  227.         WhichMenu := WhichMenu-2;
  228.     
  229.     _Select ([MenuItem o:WhichMenu m:[menu o:6]]!,1);    # Select the Restart MenuItem
  230.     
  231.     if not (gDisableAllLogging) 
  232.     begin
  233.         println "Selected the 'Restart' menu item";
  234.         Println "Rebooting CPU";
  235.     end;
  236.  
  237.     # Need a save document dialog handler
  238.     
  239.     result := releaseTarget();                # Release target so VU realizes that the target has been lost. 
  240.  
  241.     if (result <> Target_Failure)            # Released okay
  242.     begin
  243.         if not (gDisableAllLogging) 
  244.             Println "Released target successfully";
  245.  
  246.         wait(Time_to_restart);                # Short wait to allow machine to boot.
  247.         
  248.         #do an acquire with the same old target name and zone address
  249.         result := acquireTarget(target_name, target_zone);
  250.         counter := 1;
  251.         while not (result = No_Error) and (counter <= 20)# Keep trying until target is found or some other error is reported
  252.         begin
  253.             counter := counter +1;
  254.             wait(Time_to_restart);                                 # Wait 
  255.             result := acquireTarget(target_name, target_zone);
  256.         end;
  257.         
  258.         if (result = No_Error)                # Reaquired target successfully
  259.         begin
  260.                                             # Need to wait till all inits get loaded.
  261.             while not _matchBoolean([menu]);            # Match menu may not be a long enough wait
  262.             LogStr("Reaquired target successfully",4);
  263.             return (1);
  264.         end; 
  265.         else                                # Couldn't reaquire target successfully
  266.         begin
  267.             LogStr("!@#$% Couldn't aquire target",1);
  268.             Exit;
  269.         end;
  270.     end;#if released ok
  271.     else
  272.     begin
  273.         LogStr("!@#$% Couldn't release target",1);
  274.         return(0);                                 #error couldn't release target
  275.     end;
  276. end; # Restart()
  277.  
  278.  
  279. #########################################################################
  280. #                     MatchApplication(logMe,UpdateAppTitle)
  281. #========================================================================
  282. # Author:            KTA
  283. # Description:        This routine will match the current Application and,
  284. #                    if the logMe parameter is 1, will log the current
  285. #                    application name by passing it to LogStr().  If a
  286. #                    parameter is not passed, the default behavior will
  287. #                    log the application's title.  This routine will also
  288. #                    set the global gAppTitle to the application's title.
  289. #                    Output appears in the following format:
  290. #                            The current application is "Finder"
  291. # Parameters:        logMe - 1 to print the current application's title
  292. #                            0 not to print the application's title
  293. #                    UpdateAppTitle     - 1 to update the global AppTitle
  294. #                                    - 0 not to update global AppTitle
  295. # Return Value:        string holding current application's title
  296. # Examples:            MatchApplication();
  297. # Assumptions:        there is an active application
  298. #========================================================================
  299. # History:
  300. # ML    11/29/94    Added Exception Handling support
  301. #########################################################################
  302. TASK MatchApplication(logMe := 1, UpdateAppTitle :=1) 
  303. begin
  304.     try match[application t:?theAppTitle];
  305.     catch theError
  306.         ExceptionDispatcher(theError);
  307.     if (UpdateAppTitle)
  308.         global gAppTitle := theAppTitle;            #to Verify App
  309.  
  310.     if (logMe)
  311.         LogStr("The current application is '{theAppTitle}'");
  312.  
  313.     return(theAppTitle);
  314. end; # MatchApplication()
  315.  
  316.  
  317. #########################################################################
  318. #        RecordGetAboutThisMacintosh(pPhysicalRAM, pLogicalRAM, pLargestUnusedBlock, pSystemSize)
  319. #========================================================================
  320. # Author:        KTA
  321. # Description:    Makes the calls to create TCSes which record the 
  322. #                current Physical RAM, logical RAM, largest unused block, and system
  323. #                size to a Phoenix output file.
  324. # Parameters:    pPhysicalRAM - 1 Report PhysicalRAM size.
  325. #                             - 0 Don't report PhysicalRAM size.
  326. #                pLogicalRAM  - 1 Report LogicalRAM size.
  327. #                             - 0 Don't report LogicalRAM size.
  328. #                pLargestUnusedBlock  - 1 Report LargestUnusedBlock size.
  329. #                                     - 0 Don't report LargestUnusedBlock size.
  330. #                pSystemSize  - 1 Report system size.
  331. #                             - 0 Don't report system size.
  332. #                pAppName     - string name of app to get memory size of
  333. #                             - 0 Don't report application size.
  334. # Returns:        {list}       - List of sizes you've requested
  335. #                    0         - unsuccessful
  336. # Examples:        RecordGetAboutThisMacintosh();
  337. # Assumptions:    
  338. #========================================================================
  339. # History:
  340. # KTA    3/08/94        Created
  341. # ML    3/16/94        Genericized for SPEC S&L
  342. # ML    3/19/94        Added pAppname
  343. # KTA    3/28/94        Reverted back to older task as returnVal should be pass or fail
  344. # ML    4/08/94        Removed hanging TCSEnd, revised TC id's to use constants
  345. # ML    12/12/94    Revised to call _MemoryMonitor
  346. # ML    3/3/95        comment out system size until MemoryMonitor bug is fixed
  347. #                     move all memory size results to TCS Num field
  348. #########################################################################
  349. TASK RecordGetAboutThisMacintosh(pPhysicalRAM := 1, pLogicalRAM := 1, pLargestUnusedBlock := 1,pSystemSize := 1, pAppName := global gApptitle)
  350. begin
  351.     global kTCSetMemorySize, kTCTypeConfig;
  352.     returnVal := 0;
  353.     if not (_MemoryMonitor('Initialize', {1})[1])
  354.     begin
  355.         MemoryInfo := _MemoryMonitor('GetAboutThisMacintosh');
  356.         if(MemoryInfo[1] <> 0)
  357.         begin 
  358.             println "Problem making call to GetAboutThisMacintosh()";        # print error
  359.             println "Error ", MemoryInfo[1], ". ",  MemoryInfo[3] ;
  360.         end;
  361.         else
  362.         begin
  363.             returnVal := 1;
  364.             
  365.             ## PhysicalRAM
  366.             if(pPhysicalRAM)
  367.             begin
  368.                 TCSStart({1,kTCSetMemorySize, kTCTypeConfig}, "PhysicalRAM", "Memory Monitor");
  369.                 PhysicalRAM := MemoryInfo[2][1];
  370.                 TCSEnd({1,kTCSetMemorySize, kTCTypeConfig}, returnVal,,PhysicalRAM);
  371.             end;
  372.             
  373.             ## LogicalRAM
  374.             if(pLogicalRAM)
  375.             begin
  376.                 TCSStart({2,kTCSetMemorySize, kTCTypeConfig}, "LogicalRAM", "Memory Monitor");
  377.                 LogicalRAM := MemoryInfo[2][2];
  378.                 TCSEnd({2,kTCSetMemorySize, kTCTypeConfig}, returnVal,,LogicalRAM);
  379.             end;
  380.             
  381.             ## Largest Unused Block
  382.             if(pLargestUnusedBlock)
  383.             begin
  384.                 TCSStart({3,kTCSetMemorySize, kTCTypeConfig}, "Largest Unused Block", "Memory Monitor");
  385.                 LargestUnusedBlock := MemoryInfo[2][3];
  386.                 TCSEnd({3,kTCSetMemorySize, kTCTypeConfig}, returnVal,,LargestUnusedBlock);
  387.             end;
  388.             
  389. ## uncomment when Memory Monitor bug is fixed!
  390. (*
  391.             ## System Size
  392.             if(pSystemSize)
  393.             begin
  394.                 TCSStart({4,kTCSetMemorySize, kTCTypeConfig}, "System Size", "Memory Monitor");
  395.                 Processes := MemoryInfo[2][4];
  396.                 systemSize := Assoc('System', Processes);
  397.                 TCSEnd({4,kTCSetMemorySize, kTCTypeConfig}, returnVal,,,systemSize);
  398.             end;
  399. *)    
  400.             ## App Size
  401.             if pAppName
  402.             begin
  403.                 if (pAppName <> 'Unknown')
  404.                 begin
  405.                     TCSStart({5,kTCSetMemorySize, kTCTypeConfig }, "Application memory usage");
  406.                     Processes := MemoryInfo[2][4];
  407.                     AppSize := Assoc("{pAppName}", Processes);
  408.                     TCSEnd({5,kTCSetMemorySize, kTCTypeConfig },returnVal,,AppSize, pAppName);
  409.                 end; 
  410.             end;
  411.         end; 
  412.         
  413.         _MemoryMonitor('Quit');
  414.         
  415.     end; 
  416.     return (returnval);
  417. end;
  418.  
  419. ##################################################################################
  420. #                        FileShare()
  421. #=======================================================================
  422. # Author:        GS
  423. # Description:    Checks to see if fileshare was installed and whether its switched on.
  424. #
  425. # Parameters:    None
  426. # Returns:        On       :=   1
  427. #                Off      :=   0
  428. #                not Avail:=  -1
  429. #                GestaltError
  430. #=======================================================================
  431. # History:
  432. #
  433. ##################################################################################
  434. TASK FileShare()
  435. begin    
  436.     if(OnTargetInit())
  437.     begin
  438.         theResult := _OnTarget( 'FileShare' )[2];
  439.     
  440.         if(theResult = 0)
  441.             retVal := {0, "FileSharing is available but NOT ENABLED"};
  442.             
  443.         else if(theResult = 1)
  444.             retVal  := {1, "FileSharing is ON"};
  445.             
  446.         else if(theResult = 2)
  447.             retVal  := {-1, "FileSharing is not available on this machine"};
  448.             
  449.         else
  450.             retVal := {-1, "Error checking status of Filesharing"};
  451.         
  452.         _OnTarget('Quit');
  453.     end;
  454.     else 
  455.         retVal := {-2,"We Don't know, can't launch OnTarget to find out"};
  456.     
  457.     return(retVal);
  458. end;
  459.  
  460. ##################################################################################
  461. #                        MachineState()
  462. #=======================================================================
  463. # Author:        GS
  464. # Description:    Returns a list of information concerning the state of the target 
  465. #                machine.
  466. #
  467. # Parameters:    None
  468. # Returns:        Gestalt Info
  469. #=======================================================================
  470. # History:
  471. # KTA    8/3/93    Rewrote - returns instead of prints info
  472. # KTA    12/3/93    Return logical and Physical memory in Bytes.
  473. # KTA    3/23/94    Removed System Arch
  474. # ML    9/21/94 VU 2.1 gestalt support
  475. # ML    11/29/94    Added Exception Handling support
  476. # KTA    1/11/95    Removed gestalt support for VU 2.0.1 (two shorts)
  477. # KTA    1/16/95    Added support for OSVersion and ROMBuild.
  478. # KTA    1/16/95    Added pUseXTools
  479. # KTA    2/16/95    Readded MonitorInfo
  480. ##################################################################################
  481. TASK MachineState(printMachineState := 0, pUseXTools := 1)
  482. begin
  483.     try 
  484.     begin
  485.         match[system v:?OSVersion];    
  486.         match([target t:?TargetName s:?ScreenInfo]);    
  487.     end;
  488.     catch theError
  489.         ExceptionDispatcher(theError);
  490.     
  491.     CPUType            := { "CPUType", GestaltProcessorType()};
  492.     MMUType         := { "MMUType", GestaltMMUType()};
  493.     FPUType         := { "FPUType", GestaltFPUType()};
  494.     MachineType     := { "MachineType", GestaltMachineType()};
  495.  
  496.     TargetsName        := { "TargetName", TargetName};
  497.     AddrMode         := { "AddrMode", Check32Bit()[1]};
  498.     
  499.     ## logical Mem 
  500.     logMem             := (_Gestalt('lram')[2]);        
  501.     LogicalMem        := { "LogicalMem",logMem };
  502.     
  503.     ## Physical Mem
  504.     PhysMem         := (_Gestalt('ram ')[2]);
  505.     PhysicalMem        := { "PhysicalMem",PhysMem};
  506.     
  507.     VM                 := { "VM", CheckVM()[1]};
  508.     if(pUseXTools)
  509.     begin
  510.         FileSharing    := { "FileShare", FileShare()[1]};    # Requires OnTarget
  511.         ROMBuild     := { "ROMBuild", GetROMBuild()};    # Requires MemoryMonitor 1.0.5 or greater
  512.     end;
  513.     else
  514.     begin
  515.         FileSharing    := { "FileShare", -2};                # We don't know
  516.         ROMBuild     := { "ROMBuild", ''};                # We don't know        
  517.     end;
  518.     
  519.     Caches             := { "Cache",    CheckCache()[1]};
  520.     OSVersion        := { "OSVersion", OSVersion};
  521.  
  522.     MonitorInfoList := {};
  523.     for i := 1 to Card (ScreenInfo)
  524.     begin
  525.         BitDepthScreenRectList := {ScreenInfo[i].p, ScreenInfo[i].r};
  526.         MonitorInfoList[i] := BitDepthScreenRectList;
  527.     end;
  528.     MonitorInfo := { "MonitorInfo", MonitorInfoList};
  529.     
  530.     returnVal := {CPUType, MMUType, FPUType, MachineType, TargetsName, AddrMode, LogicalMem, PhysicalMem, VM, FileSharing, Caches, MonitorInfo,OSVersion,ROMBuild };
  531.     if (printMachineState)
  532.     begin
  533.         for each item in returnVal
  534.             println item[1], ":    ",item[2];
  535.     end;
  536.     
  537.     return(returnVal);
  538. end;
  539.         
  540. ##################################################################################
  541. #                        CheckCache()
  542. #=======================================================================
  543. # Author:        GS
  544. # Description:    Checks to see if caching is available and turned on, and returns 
  545. #                a value.
  546. #
  547. # Parameters:    None
  548. # Returns:        On         :=  1
  549. #                Off        :=  0
  550. #                not Avail :=  -1
  551. #                GestaltError
  552. #=======================================================================
  553. # History:
  554. #
  555. ##################################################################################
  556. TASK CheckCache()
  557. begin    
  558.     if (GestaltProcessorType() = '68040')
  559.     begin
  560.         if(OnTargetInit())
  561.         begin
  562.             toolRes := _OnTarget( 'CacheTest' )[2];
  563.             
  564.             if(toolRes = 1)
  565.                 retVal := {1, "040 Caches are ON"};
  566.             
  567.             if(toolRes = 2)
  568.                 retVal := {-1, "This isn't an '040, caching unavailable"};
  569.                 
  570.             if(toolRes = 0)
  571.                 retVal := {0, "040 Caches are OFF"};
  572.     
  573.             _OnTarget('Quit');
  574.         end;
  575.         else
  576.             retVal := {-2,"We Don't know, can't launch OnTarget to find out"};
  577.  
  578.     end;
  579.     else         
  580.         retVal := {-1, "This isn't an '040, caching unavailable"};
  581.  
  582.     return retVal;
  583. end;
  584.  
  585. #########################################################################
  586. #        RecordMonitorInfo(pReturnList)
  587. #========================================================================
  588. # Author:        ML
  589. # Description:    Makes the calls to create TCSes which record the 
  590. #                target monitors' bit depth and coordinates
  591. # Returns:        {list} - list of monitor info {{bit depth,{l,t,r,b}}}
  592. #                     0 - unsuccessful
  593. # Examples:        RecordMonitorInfo();
  594. # Assumptions:    
  595. #========================================================================
  596. # History:
  597. # ML    3/15/94        Created
  598. # KTA    1/11/95        Changed it so doesn't call MachineState() and simplified.
  599. #########################################################################
  600. TASK RecordMonitorInfo()
  601. begin
  602.     ScreenDesc := _collect([screen]);
  603.     MonitorCount := Card (ScreenDesc);
  604.     for i := 1 to MonitorCount
  605.     begin
  606.         ScreenRect := ScreenDesc[i].r;
  607.         TCSStart ({1, "Monitors", global kTCTypeConfig},"Monitor Info");
  608.         TCSEnd({ 1, "Monitors", global kTCTypeConfig},1,,ScreenDesc[i].p, "Screen ∂# '{i}' - {ScreenRect}");
  609.     end;
  610. end;
  611.  
  612. #########################################################################
  613. #             ProfileApplication() 
  614. #========================================================================
  615. #
  616. # Author:        ML
  617. #
  618. # Description:    Determines app process info, version info and
  619. #                whether it is FAT, native, or 68k.
  620. # Parameters:    appname - name of app in process list
  621. # Returns:        none
  622. # Examples:        AppInfo()
  623. # Notes:        Requires Memory Monitor and Filetool on target and 
  624. #                corresponding libs on the host.
  625. #========================================================================
  626. # History:
  627. # ML    3/17/94    Created
  628. # ML    5/10/94    Check for modal before Profiling application
  629. # ML    9/21/94 Check globals gAddSuiteInfoFieldsRE and gAdditionalSuiteInfoFT
  630. #                before resetting
  631. # ML    11/29/94    Added Exception Handling support
  632. # ML    12/12/94    removed gTestCaseLoggingMethod,
  633. #                    revised filetool calls to _Filetool
  634. #                    removed support for additional suite fields in filetool
  635. #########################################################################
  636. task ProfileApplication (appname:= global gApptitle)
  637. begin
  638.     global gAppVersion;
  639.     
  640.     if not (_matchBoolean ([window o:1 s: dialog]!))
  641.     begin
  642.     
  643.         RecordGetAboutThisMacintosh(0,0,,,appname);
  644.     
  645.         if not (_MemoryMonitor('Initialize', {1})[1]) # if memory monitor initializes ok
  646.         begin
  647.             ProcessInfo:= _MemoryMonitor('GetProcessInfo', {appname}); # get info on appname
  648.             ProcessPath:= ProcessInfo[2][7]; # path to appname's location
  649.             _MemoryMonitor('Quit');
  650.             if ProcessPath <> 'undefined' # if valid path to appname
  651.             begin
  652.                 if not (_FileTool('Initialize', {1})[1]) # if FileTool initializes ok on target
  653.                 begin
  654.                     OnPowerPC := IsPowerPC(); # what kind of Mac are we running on
  655.                     VersionInfoList:= _FileTool('ReadVersion',{ProcessPath,1}); # get appname's version info
  656.                     AppVersSaveOff := gAppVersion;
  657.                     gAppVersion:= VersionInfoList[2][1]; # get the version
  658.                     println ("The actual version of {appname} running is {gAppVersion}");
  659.                     cfrgExists:= _FileTool('ResourceExists',{ProcessPath, 'cfrg', 0}); # does appname have a code fragment resource
  660.                     codeExists:= _FileTool('ResourceExists',{ProcessPath, 'CODE', 0}); # does appname have a code resource
  661.                     _FileTool( "Quit" );    # quit FileTool on the target
  662.  
  663.                     if cfrgExists[2] # if appname has a cfrg
  664.                     begin
  665.                         if codeExists[2] # if it also has a CODE
  666.                         begin
  667.                             AppType:= "Fat";
  668.                             print ("{appname} is a FAT application");
  669.                             if OnPowerPC
  670.                                 println (" running NATIVE.");
  671.                             else
  672.                                 println (" running 68K.");
  673.                         end; # if codeExists
  674.                         else # if not codeExists
  675.                         begin
  676.                             AppType:= "PPC";
  677.                             println ("{appname} is a purely native application running NATIVE.");
  678.                         end; # not codeExists
  679.                     end; # if cfrgExists
  680.                     else # if not cfrgExists
  681.                     begin
  682.                         AppType:= "68k";
  683.                         print ("{appname} is a 68k application");
  684.                         if OnPowerPC
  685.                             println (" running EMULATED.");
  686.                         else
  687.                             println (".");
  688.                     end; # if not cfrgExists
  689.                 end; # if FileTool initializes ok
  690.             end; # if valid path to appname
  691.         end; # if memory monitor initializes ok
  692.         
  693.         if not global gAddSuiteInfoFieldsRE
  694.             global gAddSuiteInfoFieldsRE := {};
  695.             
  696.         if global gAppTitleSaveOff <> gApptitle # if gAppTitle has been modified after launch
  697.             gAddSuiteInfoFieldsRE := gAddSuiteInfoFieldsRE + {{ 'AppName', gAppTitle}};
  698.     
  699.         if AppVersSaveOff <> gAppVersion # if gAppVersion has been modified after launch
  700.             gAddSuiteInfoFieldsRE := gAddSuiteInfoFieldsRE + {{ 'AppVers', gAppVersion}};
  701.     
  702.         if AppType
  703.             gAddSuiteInfoFieldsRE := gAddSuiteInfoFieldsRE + {{ 'CodeType', AppType}};
  704.     
  705.     end; # if not match [window o:1 s: dialog]!
  706.     else
  707.         println "WARNING - Modal dialog present - not profiling application";
  708. end; # task ProfileApplication
  709.  
  710.  
  711. #########################################################################
  712. #             GetROMBuild() 
  713. #========================================================================
  714. # Description:    Reads the target ROM and returns the build of the ROM.
  715. #                Note: this is not the ROM Version as returned by Gestalt.
  716. #                Reads a short at offset 18 from ROM base @ 0x2AE+Ox12, then
  717. #                returns the formatted results.
  718. # Parameters:    none
  719. # Returns:        Formated string which is the build of the ROM.
  720. # Examples:        GetROMBuild()
  721. # Notes:        Requires Memory Monitor version 1.0.5 or greater (reading 
  722. #                ROM addresses was added to this build)
  723. #========================================================================
  724. # History:
  725. # KTA    1/31/95    Print error message when old version of MemoryMonitor
  726. # ML    2/15/95    if fail, return string instead of undefined.
  727. #########################################################################
  728. task GetROMBuild()
  729. Begin    
  730.         ###    Read Pointer to ROM base from low mem global @ 0x2AE
  731.     x := _MemoryMonitor('ReadBytes',{ {0, 686}, 4 });    
  732.     if (x[1] = 0)
  733.     begin
  734.         ByteList := x[2];
  735.         ROMBaseAddr := {    (ByteList[1] << 8) + ByteList[2],     # High word
  736.                             (ByteList[3] << 8) + ByteList[4] };    # Low word
  737.  
  738.             ###    Read Rom build directly from ROM,
  739.             ###    read a short at offset 18 from ROM base @ 0x2AE+Ox12
  740.         ROMBuildAddr := { ROMBaseAddr[1], ROMBaseAddr[2] + 18 };
  741.         x := _MemoryMonitor('ReadBytes',{ ROMBuildAddr, 2 });    
  742.              _MemoryMonitor('Quit');    
  743.  
  744.         if (x[1] = 0)
  745.         begin
  746.             ByteList := x[2];
  747.             ROMBuild := (ByteList[1] << 8) + ByteList[2];
  748.             BuildStr := NumToStr( ROMBuild, 16 );  # Get Hex string of ROM build            
  749.             BuildStr := StringAfterChar(BuildStr, 'x');    # Sring the 0x from buildstring
  750.  
  751.             if BuildStr[1] ~= /[0-9]/
  752.                 dot := '.';            #e.g. 2.1A2 (0x21A2)
  753.             else 
  754.                 dot := '';            #e.g. D11C4 (0xDBC4)
  755.                 
  756.             PadCount := 4 - card BuildStr;
  757.             
  758.             for i := 1 to PadCount    #pad to 4 hex digits
  759.                 BuildStr := '0' + BuildStr;
  760.                 
  761.             BuildStr := BuildStr[1] + dot + "{StrToNum( '0x' + BuildStr[2] )}" +
  762.                          BuildStr[3] +       "{StrToNum( '0x' + BuildStr[4] )}";
  763.             
  764.             return BuildStr;
  765.         end;
  766.         else
  767.             return "ERROR: MemMon problem";
  768.         
  769.     end;
  770.     else if(x[1] = 3)
  771.     begin
  772.         println "!@#$% ∂'WARNING: You may be running an old version of the Memory Monitor ( use version 1.0.5 or greater to read the ROMBuild )";
  773.         return 'ERROR: Old MemoryMon';
  774.     end;
  775.     else
  776.         return "ERROR: MemMon problem";
  777. end;
  778.  
  779. #########################################################################
  780. #                 IsPowerPC()
  781. #=======================================================================
  782. # Author:          KTA
  783. # Description:    Makes a call to ProcessorType() to determine if the
  784. #                target system is PowerPC or not
  785. # Parameters:    none
  786. # Returns:        0 - not PowerPC
  787. #                1 - PowerPC
  788. #=======================================================================
  789. # History:
  790. # KTA    12/01/93    Created
  791. ########################################################################
  792. TASK IsPowerPC()
  793. begin
  794.     returnVal := 0;
  795.     sysa := GestaltSystemArchitecture();
  796.     if(sysa = 2)
  797.         returnVal := 1;
  798.     return(returnVal);
  799. end;
  800.         
  801. #########################################################################
  802. #                 IsSystem7()
  803. #=======================================================================
  804. # Author:          KTA
  805. # Description:    Makes a gestalt call to to determine if the
  806. #                target system is system 7.0 or greater. 
  807. # Parameters:    none
  808. # Returns:        0 - not system 7.0 or greater
  809. #                1 - system 7.0 or greater
  810. #                Note: the global gIsSys7 will also be set as a side effect 
  811. #                    of calling this task.
  812. #=======================================================================
  813. # History:
  814. # KTA    4/11/95    Created
  815. ########################################################################
  816. TASK IsSystem7()
  817. begin
  818.     SystemCheck := _Gestalt('sysv');
  819.     if (SystemCheck[1] = 0)
  820.     begin
  821.         if (SystemCheck[2] >= 1792)    # 1792 is 0700 in Hex for system 7.0
  822.             Global gIsSys7 := 1;     # System7 features are available
  823.         else
  824.             Global gIsSys7 := 0;     # System7 features are not available
  825.     end;
  826.     return(gIsSys7);
  827. end;